﻿using System;
using System.Collections.Generic;
using System.Linq;

using Fuse8.DomainFramework.Common.Locator;

using Fuse8.ContentManagementFramework.Domain;
using Fuse8.ContentManagementFramework.Domain.Commands;

namespace Fuse8.ContentManagementFramework.BizFacade.Services
{
    public class CmsMediaService : CmsSiteBusinessService<CmsMedia>
    {
        public override CmsMedia FindOne(int id)
        {
            var command = DependencyServiceLocator.Current.GetInstance<CmsMediaSelectOneCommand>();

            var commandParameter = new CmsMediaSelectCommandParameter();

            commandParameter.MediaId = id;
            
            SiteAwareEntityObjectMediator.SetSiteEntity(commandParameter);

            command.ConfigureCommand(commandParameter);

            return FindOne(command);
        }

        public override IEnumerable<CmsMedia> FindAll()
        {
            var command = DependencyServiceLocator.Current.GetInstance<CmsMediaSelectAllCommand>();

            var commandParameter = new CmsMediaSelectCommandParameter();

            SiteAwareEntityObjectMediator.SetSiteEntity(commandParameter);

            command.ConfigureCommand(commandParameter);

            return Find(command);
        }

        public IEnumerable<CmsMedia> FindWithMimeType(string mimeType)
        {
            var command = DependencyServiceLocator.Current.GetInstance<CmsMediaSelectAllCommand>();

            var commandParameter = new CmsMediaSelectCommandParameter();

            commandParameter.MimeType = mimeType;

            SiteAwareEntityObjectMediator.SetSiteEntity(commandParameter);

            command.ConfigureCommand(commandParameter);

            return Find(command);
        }

        public IEnumerable<CmsMedia> FindAllWithSubfolders()
        {
            var command = DependencyServiceLocator.Current.GetInstance<CmsMediaSelectAllCommand>();

            var commandParameter = new CmsMediaSelectCommandParameter();

            commandParameter.WithSubfolders = true;

            SiteAwareEntityObjectMediator.SetSiteEntity(commandParameter);

            command.ConfigureCommand(commandParameter);

            return Find(command);
        }

    }
}
